<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col v-if="form.firstInvest === 'Y'" :span="24">
          <el-form-item :label="$t('首轮投资名称')" prop="firstInvestName">
            <el-input v-model="form.firstInvestName" :placeholer="$t('首轮投资名称')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('新增投资名称')" prop="newInvestName">
            <el-input v-model="form.newInvestName" :placeholer="$t('新增投资名称')" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">{{ $t('取消') }}</el-button>
      <el-button type="primary" @click="submitForm">{{ $t('确定') }}</el-button>
    </div>
  </div>
</template>

<script>

import { getFirstInvestName, saveInvestRound } from '@/api/act/busFlow/wfBusNode'
export default {
  components: {

  },
  data() {
    return {
      form: {
        busId: undefined,
        busType: undefined,
        firstInvestName: undefined,
        newInvestName: undefined,
        firstInvest: 'N'
      },
      loading: false,
      // 表单校验
      rules: {
        firstInvestName: [{ required: true, message: this.$t('必填信息'), trigger: ['blur'] }],
        newInvestName: [{ required: true, message: this.$t('必填信息'), trigger: ['blur'] }]
      }
    }
  },
  created() {

  },
  methods: {
    // 初始化数据
    init(busId, busType) {
      getFirstInvestName(busId, busType).then(response => {
        this.form.busId = busId
        this.form.busType = busType
        if (response.data) {
          this.form.firstInvest = 'N'
        } else {
          this.form.firstInvest = 'Y'
        }
      })
      // if (data != null && data.id !== undefined && data.id !== '') {
      //   console.log('处理业务')
      // } else {
      //   this.reset()
      // }
    },
    // 表单重置
    reset() {
      this.form = {
        firstInvestName: undefined,
        newInvestName: undefined
      }
      this.resetForm('form')
      this.bfContractPlanInvestMainOptions = []
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.addInvestOpen = false
      this.reset()
    },
    // 关闭form页面
    closeForm() {
      // 关闭form页面遮罩层
      this.loading = false
      // 关闭form页面
      this.$parent.$parent.addInvestOpen = false
      // 刷新list页面
      // this.$parent.$parent.getList()
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.loading = true
          saveInvestRound(this.form).then(response => {
            this.cancel()
            this.$parent.$parent.getParentNode(null, response.data.busId, response.data.id)
            this.msgSuccess(this.$t('操作成功'))
            this.loading = false
          })
        }
      })
    }
  }
}
</script>
